var express = require('express');
var router = express.Router();
var adminModel=require('../models/admin.model');
router.get('/', function(req, res, next) {

  res.render('login.html', { title: 'Express' });
});
router.post('/dologin.html', function(req, res, next) {
    var post=req.body;
    req.session.user_id=post.username;

    adminModel.getUserInfoByUserName(post.username,function(error,data){
        var md5 = require('md5');
        if(data.length>0&&data[0].name==post.username){
            return res.redirect('/index.html');
        }else{
            res.send('没有数据');
        }
    })
});
router.get('/index.html',function(req,res,next){
    adminModel.getUserList(function(error,data){
        // res.send("eeee");

        //console.log(data)
        //data  [{"id":1,"name":"root"},{"id":2,"name":"admin"}]
        res.render('index.html',{ title: 'Express',user:JSON.stringify(data) })
    })
})
module.exports = router;
